package com.day06;

import java.util.Map;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.HashMap;
import java.util.Comparator;

public class zuo {
    public static void main(String[] args) {
        List list = new ArrayList();
        //添加学生信息
        Student student1 = new Student(1, "jack", 25, '女', 50.4);
        Student student2 = new Student(2, "smith", 23, '男', 0);
        Student student3 = new Student(3, "tom", 22, '男', 60.3);
        Student student4 = new Student(4, "marry", 22, '女', 0);
        Student student5 = new Student(5, "mila", 24, '女', 38.9);
        //讲学生的信息加入 list集合中
        list.add(student1);
        list.add(student2);
        list.add(student3);
        list.add(student4);
        list.add(student5);
        //输出list
        System.out.println("====list的信息如下====");
        System.out.println(list);
        //学生成绩排序(从小到大)
        list.sort(new Comparator() {
            @Override
            public int compare(Object o1, Object o2) {
                Student student1 = (Student) o1;
                Student student2 = (Student) o2;
                double scoreVal = student1.getScore() - student2.getScore();
                if (scoreVal > 0) return 1;
                else if (scoreVal < 0) return -1;
                else return 0;
            }
        });
        //再次输出list
        System.out.println("====按学生成绩从小到大输出====");
        System.out.println(list);

        //删除学生成绩为0


        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Student student = (Student) iterator.next();
            if (student.getScore() == 0) {
                iterator.remove();
            }
        }
        System.out.println("====删除学生成绩为0的信息====");
        System.out.println(list);

        //将学生信息加入到 map中
        Map<String, Object> map = new HashMap<>();
        map.put("1", student1);
        map.put("2", student2);
        map.put("3", student3);
        map.put("4", student4);
        map.put("5", student5);
        System.out.println("====map中的信息如下====");
        System.out.println(map);

    }
}
